<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title>教务管理系统</title>
    <link rel="stylesheet" href="layui/css/layui.css?t=20180530-2" media="all" th:href="@{/web/layui/css/layui.css}">
    <link rel="stylesheet" href="css/admin.css?t=20180530-2" media="all" th:href="@{/web/css/admin.css}">
    <link rel="stylesheet" href="css/l-style.css" th:href="@{/web/css/l-style.css}"/>
    <link rel="stylesheet" th:href="@{/web/js/ztree/zTreeStyle.css}"/>
    <link rel="stylesheet" th:href="@{/web/js/ztree/metroStyle/metroStyle.css}"/>
    <script type="text/javascript" src="js/echarts.js" th:src="@{/web/js/echarts.js}"></script>
    <link rel="stylesheet" href="css/l-style_8.css" th:href="@{/web/css/l-style_8.css}"/>
</head>
<style>
    .layui-input-block {
        margin-right: 50px;
    }
</style>
<body>

<!-- 主体内容 -->
<div class="layui-fluid dang_fluid" lay-title="表格列表1">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md12">
            <div class="item_head border_all">
                <h3 class="item_tit">功能权限管理</h3>
            </div>
            <div class="item_box mT5">
                <div style="margin: 20px 50px;display: inline-block">
                    <button class="layui-btn layui-btn-normal" id="addFunction">添加权限</button>
                </div>
                <div style="padding:5px;margin-left: 30%;margin-bottom: 50px">
                    <ul id="functionTree" class="ztree"></ul>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="addWindow" style="display: none;margin-top: 30px">
    <form class="layui-form" action="" lay-filter="fromTest">
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="title" autocomplete="off" placeholder="请输入名称"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否生成菜单</label>
            <div class="layui-input-block">
                <select name="interest" lay-filter="aihao">
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">优先级</label>
            <div class="layui-input-block">
                <input type="text" name="zindex" lay-verify="title" autocomplete="off" placeholder="请输入优先级"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">代码</label>
            <div class="layui-input-block">
                <input type="text" name="code" lay-verify="title" autocomplete="off" placeholder="请输入代码"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">父功能点</label>
            <div class="layui-input-block">
                <select name="pid" lay-filter="parentFunction">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <input type="text" name="description" lay-verify="title" autocomplete="off" placeholder="请输入描述"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">访问路径</label>
            <div class="layui-input-block">
                <input type="text" name="page" lay-verify="title" autocomplete="off" placeholder="请输入访问路径"
                       class="layui-input">
            </div>
        </div>
        <input type="hidden" name="id"/>
    </form>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">增加</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">修改</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">作废</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">复原</button>
    </div>
</script>
<script th:src="@{/web/js/jquery.min.js}"></script>
<script th:src="@{/web/layui/layui.js}"></script>
<script th:src="@{/web/layui/layui.all.js}"></script>
<script type="text/javascript" th:src="@{/web/js/l-index.js}"></script>
<script type="text/javascript" th:src="@{/web/js/web/common/common.js}"></script>
<script type="text/javascript" th:src="@{/web/js/ztree/jquery.ztree.all-3.5.js}"></script>
<script>
</script>
<script th:src="@{/web/js/web/admin/functionLib.js}"></script>
<script th:inline="javascript">
    selectAjaxData("select", "http://localhost:8080/function/listajax", "parentFunction", null)
    functionLib.load();

    $(function () {
        $("#addFunction").click(function () {
                collegeWindos("添加权限", "#addWindow", null)
            }
        )
    })

    function collegeWindos(title, content, data) {
        layer.open({
            type: 1 //此处以iframe举例
            , title: title
            , area: ['350px', '500px']
            , shade: 0
            , maxmin: true
            , content: $(content)
            , btn: ['确定'],
            yes: function (index, layero) {
                layui.use('form', function () {
                    var form = layui.form;
                    let dataForm = form.val("fromTest");
                    $.ajax({
                        type: "post",
                        url: "http://localhost:8080/function/update",
                        data: dataForm,
                        success(data) {
                            if (data.status == 1) {
                                layer.close(index);
                                layer.alert(data.msg)
                                window.location.reload()
                            }
                        }, error(data) {
                            layui.table.reload('exampleTable')
                            layer.close(index)
                            layer.alert("操作失败")
                        }
                    });
                });
            },
            btnAlign: 'c',
            closeBtn: 1,
            shade: 0.8,
            shadeClose: true
            , scrollbar: true
            , success: function (layero, index) {
                layui.use('form', function () {
                    var form = layui.form;
                    let dataFrom = form.val("fromTest", data == null ? {
                        "id": null,
                        "name": null,
                        "pid": null,
                        "code": null,
                        "description": null,
                        "page": null,
                        "zindex": null,
                    } : data);
                });
            }
        })
    }

    function confrimWindow(content, data) {
        layer.confirm(content, {
            btn: ["确定", "取消"]
        }, function (index, layero) {
            $.ajax({
                type: "get",
                url: "http://localhost:8080/function/delete?id=" + data.id,
                success(data) {
                    if (data.status == 1) {
                        layer.close(index);
                        window.location.reload()
                    }
                },
                error(data) {

                }
            })
            ;
        }, function () {
            layer.close()
        })
    }
</script>
</body>

</html>